package com.archive.forum.controller;

import com.archive.forum.dto.ResultDTO;
import com.archive.forum.exception.ExceptionEnum;
import com.archive.forum.model.User;
import com.archive.forum.service.LikeService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/like")
public class LikeController {
    @Autowired
    private LikeService likeService;

    @PostMapping
    public ResultDTO like(@RequestParam(name = "targetId") Integer targetId,
                          @RequestParam(name = "type") Integer type,
                          HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        if (user == null) {
            return ResultDTO.errorOf(ExceptionEnum.NOT_LOGIN);
        }
        return likeService.like(user.getId(), targetId, type);
    }
}